package org.thukari;

import com.alibaba.excel.EasyExcel;
import org.thukari.controller.DealDataListener;
import org.thukari.controller.DemoDataListener;
import org.thukari.entity.DealData;
import org.thukari.entity.DemoData;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class GetStarted {

    //根据输入判断是否需要跨月，由此来确定月份
    public static int standardDate = Calendar.MARCH;

    public static void programIn() {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println("请输入1或2来决定生成的表格，1生成成交通报及成交清单，2生成成交统计，输入0退出");
            int i = scanner.nextInt();
            if (i == 0) {
                scanner.close();
                System.exit(0);
            } else if (i == 1) {
                System.out.println("注意请确认原始商机单清单在sheet2，原始成交清单在sheet1");
            } else if (i == 2) {
                System.out.println("注意请放入完整的成交清单");
            } else {
                System.out.println("输入不符合预期");
                programIn();
            }

            System.out.println("是否需要跨月处理，是请输入1，否请输入0？（例如在2月时做1月的总结）");
            int m = scanner.nextInt();
            if (m == 1) {
                Date date = new Date();
                if (date.getMonth() != Calendar.JANUARY) {
                    standardDate = date.getMonth() - 1;
                } else {
                    standardDate = Calendar.DECEMBER;
                }
            }else if (m == 0){
                standardDate = new Date().getMonth();
            }else {
                System.out.println("输入错误，请重新尝试");
                scanner.close();
                Thread.sleep(3000);
                System.exit(0);
            }
            System.out.println("请输入要处理的文件路径（可以将文件图标直接拖入窗口）：");
            String fileName = scanner.next();
            excelProcess(i, fileName);
            System.out.println("所需信息收集完毕，文件将默认生成在桌面（文件名默认为out.xlsx）");
            System.out.println("生成完成，稍后自动退出");
            Thread.sleep(3000);
        } catch (Exception e) {
            System.out.println("输入错误，请重新启动程序尝试");
            System.exit(0);
        }
    }

    private static void excelProcess(int i, String fileName) {
        if (i == 1) {
            EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).doReadAll();
        }
        if (i == 2) {
            EasyExcel.read(fileName, DealData.class, new DealDataListener()).doReadAll();
        }
    }

}
